﻿#pragma once
#include "AsGraphicsBasics.h"

__AS_JY(Update 2023.1.7)
namespace AsGraphicsMath {

	struct AS_GRAPHICS_API Param {
		static constexpr const double PI = 3.141592654;
	};

	AS_GRAPHICS_API QPoint getStartPos_HVCenter(const QSize& outside_size, const QSize& inside_size);
	AS_GRAPHICS_API QRect toPositiveRect(const QPoint& begin, const QPoint& end);
	AS_GRAPHICS_API QRectF toPositiveRect(const QPointF& begin, const QPointF& end);

	AS_GRAPHICS_API bool iszero(float f);
	AS_GRAPHICS_API bool iszero(double f);
	AS_GRAPHICS_API double distance(const QPointF& p1, const QPointF& p2);

	class AS_GRAPHICS_API Line {
	public:
		Line();
		Line(double a, double b, double c);

	private:
		QPointF m_p1;
		QPointF m_p2;
		double m_a;
		double m_b;
		double m_c;
		double m_k;

	public:
		static Line fromKB(double k, double b);
		static Line fromPoints(const QPointF& p1, const QPointF&p2);

	public:
		bool isValid() const;
		QPointF getP1() const;
		QPointF getP2() const;
		double getA() const;
		double getB() const;
		double getC() const;
		double getK() const;
		double getY(double x) const;
		double getX(double y) const;

	public:
		// 获取线段长度
		double getLength() const;
		// 获取点到直线距离
		double getDistance(const QPointF& p) const;

	public:
		// 是否竖直
		bool isVertical() const;
		// 是否水平
		bool isHorizontal() const;
		// 是否平行
		bool isParallel(const Line& line) const;
		// 是否相交
		bool isIntersection(const Line& line) const;
		// 是否重合
		bool isCoincide(const Line& line) const;
		// 是否垂直
		bool isOrthogonality(const Line& line) const;
		// 获取交点
		QPointF getNode(const Line& line) const;
		// 获取夹角
		double getAngle(const Line& line) const;

	public:
		QPointF getAltitudePoint(const QPointF& p) const;
		QVector<QPointF> getPoints(QRectF range, int interval = 1) const;

	};

	AS_GRAPHICS_API QRectF combineBoundingRect(const QRectF& boundingRect1, const QRectF& boundingRect2);

};

namespace AsGraphicsMath {

	template <typename _PrivateType>
	_PrivateType minimum(_PrivateType v1, _PrivateType v2) {
		return v1 < v2 ? v1 : v2;
	}
	template <typename _PrivateType>
	_PrivateType maxmum(_PrivateType v1, _PrivateType v2) {
		return v1 > v2 ? v1 : v2;
	}

};

namespace AGM = AsGraphicsMath;